package com.sgb.kjwl.view.ui.adapter.supplier3;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;

import com.google.gson.Gson;
import com.sgb.alimaplibrary.util.ToastUtil;
import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.supplier3.SupplierRecommendEntity;
import com.sgb.kjwl.model.entity.transport.common.AddressItem;
import com.sgb.kjwl.utils.MapUtils;
import com.sgb.kjwl.view.ui.activity.WebViewX5Fragment;
import com.sgb.kjwl.view.ui.activity.manage.WebsiteInfoActivity;
import com.sgb.kjwl.view.widget.mapdialog.Constant;
import com.sgb.kjwl.view.widget.mapdialog.MapSelcetDialog;
import com.sgb.kjwl.view.widget.transport.MapNavigationDialog;
import com.swgk.core.helper.OnMultiClickListener;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.MToast;

import java.util.List;

/**
 * @author Administrator
 */
public class SupplierRecommendMapAdapter extends BaseRecycleAdapter<SupplierRecommendEntity> {
    private ActionCallBack actionCallBack;
    private MapNavigationDialog mNavigationDialog;

    public void setActionCallBack(ActionCallBack actionCallBack) {
        this.actionCallBack = actionCallBack;
    }

    public SupplierRecommendMapAdapter(Context context, List<SupplierRecommendEntity> datas) {
        super(context, R.layout.item_supplier_recommend_map, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, final SupplierRecommendEntity entity) {
        if (TextUtils.isEmpty(entity.getAuthYear())) {
            holder.getView(R.id.authYear).setVisibility(View.GONE);
        } else {
            holder.getView(R.id.authYear).setVisibility(View.VISIBLE);
        }

        if ("1".equals(entity.getSelfSupportTag())) {
            holder.setVisible(R.id.image_ziying, true);
        } else {
            holder.setVisible(R.id.image_ziying, false);
        }

        holder.getView(R.id.map_go).setOnClickListener(v -> {
            //导航弹窗初始化
            if (mNavigationDialog == null)
                mNavigationDialog = new MapNavigationDialog(context);
            AddressItem item = new AddressItem(Double.parseDouble(entity.getLatitude()), Double.parseDouble(entity.getLongitude()),entity.getAddress());
            mNavigationDialog.navigation(item);
          /*  MapSelcetDialog dialog = new MapSelcetDialog(context);
            dialog.setOnItemClickListener(type -> {
                if (type == Constant.MAPGD) {
                    if (MapUtils.isGdMapInstalled()) {
                        MapUtils.openGaoDeNavi(context, 0, 0, null, Double.parseDouble(entity.getLatitude()), Double.parseDouble(entity.getLongitude()), entity.getAddress());
                    } else {
                        MToast.showToast(context, "当前手机未安装高德地图");
                    }
                } else if (type == Constant.MAPBD) {
                    if (MapUtils.isBdMapInstalled()) {
                        MapUtils.openBaiDuNavi(context, 0, 0, null, Double.parseDouble(entity.getLatitude()), Double.parseDouble(entity.getLongitude()), entity.getAddress());
                    } else {
                        MToast.showToast(context, "当前手机未安装百度地图");
                    }
                } else if (type == Constant.MAPTENCENT) {
                    if (MapUtils.isTencentMapInstalled()) {
                        MapUtils.openTencentMap(context, 0, 0, null, Double.parseDouble(entity.getLatitude()), Double.parseDouble(entity.getLongitude()), entity.getAddress());
                    } else {
                        MToast.showToast(context, "当前手机未安装腾讯地图");
                    }
                }
            });*/


        });

        holder.getView(R.id.tv_phone).setOnClickListener(v -> {
            if (actionCallBack != null) {
                actionCallBack.onClickedCallBack(1, entity);
            }
        });

        holder.getView(R.id.tv_xunjia).setOnClickListener(new OnMultiClickListener() {
            @Override
            public void onMultiClick(View v) {
                if (actionCallBack != null) {
                    actionCallBack.onClickedCallBack(2, entity);
                }
            }
        });
        holder.getView(R.id.tv_hanxun).setOnClickListener(v -> {
            if (actionCallBack != null) {
                actionCallBack.onClickedCallBack(3, entity);
            }
        });
        holder.getView(R.id.tv_shenqing).setOnClickListener(v -> {
            if (actionCallBack != null) {
                actionCallBack.onClickedCallBack(4, entity);
            }
        });
        holder.getView(R.id.tv_join).setOnClickListener(v -> {
            if (actionCallBack != null) {
                actionCallBack.onClickedCallBack(5, entity);
            }
        });

        holder.getView(R.id.title_view).setOnClickListener(v -> {
            if (actionCallBack != null) {
                actionCallBack.onClickedCallBack(6, entity);
            }
        });
        holder.setBinding(BR.viewModel, entity);
    }

    public interface ActionCallBack {
        /**
         * 接口回调
         *
         * @param type
         * @param recommendEntity
         */
        void onClickedCallBack(int type, SupplierRecommendEntity recommendEntity);
    }

}
